package routers

import (
	"mvip-route/control"
	"mvip-route/middlewares"

	"github.com/gin-gonic/gin"
)

// DefaultRoutersInit 网关路由
func DefaultRoutersInit(r *gin.Engine, dameRedContr *control.DameRedContr, dameDomainContr *control.DamDomainIpContr) {
	// 添加根路径中间件 只对 / 路由应用中间件
	rootRouters := r.Group("/", middlewares.RedirectMiddlewares())
	{
		rootRouters.GET("", control.Redirect{}.RedirectHandler)
	}

	// http://qq.localhost.com/ff1/?target=http://ww.localhost.com/page?idcard=10004
	defaultRouters := r.Group("/:path", middlewares.SldMiddlewares())
	{
		// 重定向链接
		defaultRouters.GET("", control.Redirect{}.RedirectTarget)

		// 检测链接是否被屏蔽
		defaultRouters.GET("/check", control.WebServer{}.UrlCheck)
	}

	// 请求page 则是其他地方重定向过来的
	targetRouters := r.Group("/page")
	{
		targetRouters.GET("", control.Forward{}.ForwardPage)
		targetRouters.GET("/down", control.Forward{}.DownPage)
	}

	cpsRouters := r.Group("/cps")
	{
		cpsRouters.GET("", control.Forward{}.ToCps)
	}

	dameRedRouters := r.Group("/pQ1rS2/dame_red")
	{
		// 创建 dame_red
		dameRedRouters.POST("", dameRedContr.CreateDameRed)
		// 获取所有 dame_red 列表
		dameRedRouters.GET("", dameRedContr.GetDameReds)
		dameRedRouters.GET("/get", dameRedContr.GetDameRed)

		// 更新 dame_red
		dameRedRouters.PUT("/:id", dameRedContr.UpdateDameRed)
		// 删除 dame_red
		dameRedRouters.PUT("/d/:id", dameRedContr.DeleteDameRed)
	}
	dameDomainRouters := r.Group("/pQ1rS2/dame_domain")
	{
		dameDomainRouters.POST("", dameDomainContr.CreateDamDomain)
		dameDomainRouters.GET("", dameDomainContr.GetDamDomain)
		dameDomainRouters.PUT("/d/:id", dameDomainContr.DeleteDamDomain)
	}
	// 日志
	logGroup := r.Group("/log")
	logCtrl := control.LogContr{}
	{
		logGroup.GET("/list", logCtrl.LogList)
	}
}
